<template>
	<view>
		<navbar :title="title">
		</navbar>
		<view style="padding: 10px;">
			<view style="padding: 10px 0;" v-if="title=='问题反馈'">
				<u-radio-group v-model="radio" placement="row">
					<u-radio :customStyle="{marginRight: '10px'}" v-for="(item, index) in radiolist" :key="index"
						:label="item.name" :name="item.name">
					</u-radio>
				</u-radio-group>
			</view>
			<u-alert title="设备信息" type="info" :description="device" style="margin: 10px 0;"></u-alert>
			<u--textarea v-model="content" placeholder="请输入反馈内容" maxlength="500" autoHeight
				style="margin: 10px 0;"></u--textarea>
			<u-button text="反馈" type="primary" @click="feedback"></u-button>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database();
	import ase from '@/common/ar-aes/ar-aes.js'
	export default {
		onLoad(op) {
			if (op.id == null) {
				this.title = "问题反馈"
			} else if (op.type == 'comment') {
				this.title = "评论举报"
				this.id = op.id
			} else if (op.type == 'pan') {
				this.title = "资源举报"
				this.id = op.id
			} else if (op.type == 'file') {
				this.title = "文件举报"
				this.id = op.id
			}
			this.getdevice()
		},
		methods: {
			async feedback() {
				if (this.content == null) {
					this.message('内容为空', 'errot')
					return null
				}
				var that = this;
				let form = {
					title: this.title,
					to: "641af5fef43e603fbe9f5f53"
				}
				if (this.title == "问题反馈") {
					form.content = `设备信息:${this.device}\n反馈内容:${this.content}`
				} else if (this.title == "评论举报") {
					form.content = `设备信息:${this.device}\n反馈内容:${this.content}\n评论id:${this.id}`,
						form.msg_type = "morecomment"
					form.msg_id = this.id
				} else if (this.title == "文件举报") {
					form.content = `设备信息:${this.device}\n反馈内容:${this.content}\n文件id:${this.id}`,
						form.msg_type = "filedetail"
					form.msg_id = this.id
				} else if (this.title == "需求举报") {
					form.content = `设备信息:${this.device}\n反馈内容:${this.content}\n需求id:${this.id}`,
						form.msg_type = "articledetail"
					form.msg_id = this.id
				}
				uniCloud.callFunction({
					name: 'message',
					data: {
						data: ase.encrypt(JSON.stringify({
							type: "send",
							form: form
						}), 'yclycl1314520520', '9740022097400220')
					},
					success(res) {
						that.content = null
						that.message("反馈成功").then((res) => {
							setTimeout(function() {
								uni.navigateBack({
									delta: 1
								})
							}, 500)
						})
					}
				});
			},
			getdevice() {
				var data = uni.getDeviceInfo()
				if (data.deviceBrand == null) {
					data.deviceBrand = "获取失败"
				}
				this.device = `品牌:${data.deviceBrand}\n型号:${data.deviceModel}\n系统:${data.system}\n平台:${data.platform}`
			}
		},
		data() {
			return {
				id: null,
				device: null,
				content: null,
				radiolist: [{
					name: "应用BUG"
				}, {
					name: "运营建议"
				}, {
					name: "其他问题"
				}],
				radio: "应用BUG",
				title: null
			};
		}
	}
</script>

<style>
	page {
		background-color: white;
	}
</style>